//手机号验证
function verifyPhone(phone,callback) {
    //拼装 json
    let json = {"phone":phone};
    $.getJSON("http://localhost:7777/hy-frontuser-consumer/ums_member/phoneVerify.action",json,function (res) {
        callback(res);
    });
};

//手机号密码登录
function phonePwdLogin(json,callback) {
    $.post("http://localhost:7777/hy-frontuser-consumer/ums_member/phonePwdLogin.action",json,function (res) {
        let css_class = {
            one:'.verify-box1',
            two:'.pwd-box',
            three:'.pwd-box'
        };
        callback(res,css_class);
    },"json");
};

//后台接口 对应状态码-对应操作
function operation(res,css_class) {
    /**
     * 响应编码 100-请求成功 101-请求异常 102-无数据 103-未登录 104-请求失败 105-授权失败
     */
    let class1;
    if (res.code == 100){
        //登录成功  跳转主页(后台返回地址)
        window.location.href = res.redirectUrl;
    }else if(res.code == 101){
        class1 = css_class.one;
    }else if(res.code == 102){
        class1 = css_class.two;
    }else {
        class1 = css_class.three;
    }
    //登录失败
    if (res.code != 100){
        //提示文本
        ShowTips(res.message, class1);
    }
};

//发送短信验证码
function sendSms(data){
    $.post("http://localhost:7777/hy-frontuser-consumer/note/sendCode.do",data,function (res) {
        if (res.code == 100) {     // 发送成功
            ShowTips("<span style='color:#232628'>验证码已发送请查收</span>", ".code-box");
            counter = 0;
            $("#getcodeBtn").hide();
            $("#regetcode").html("90");
            $("#prompt_info").show();
            $("#phoneSmsCode").focus();
            interval = window.setInterval(intervalFunc, 1000);
        }  else {
            //res.code = 101 请求异常
            //res.code = 104 验证码获取失败
            ShowTips(res.message, ".code-box");
        }
    },"json");
};

//短信验证码登录
function smsLogin(data){
  $.post("http://localhost:7777/hy-frontuser-consumer/ums_member/noteVerify.action",data,function (res) {
      let css_class = {
          one:'',
          two:'.code-box',
          three:'.code-box'
      };
      operation(res,css_class);
  },"json");
};

//第三方登录
function third_Login(source) {
    $.getJSON("http://localhost:7777/hy-frontuser-provider/oauth/render/"+source,null,function (res) {
        if (res.code == 100){
            window.location.href = res.redirectUrl;
        }else{
            //提示文本
            layer.msg(res.message);
        };
    });
};